package net.trustie.model;

import java.util.ArrayList;
import java.util.List;

import net.trustie.utils.DateHandler;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import us.codecraft.webmagic.model.annotation.ExtractBy;
import core.AfterExtractor;
import core.Page;
import core.ValidateExtractor;

public class SoftPediaMobile_Model implements AfterExtractor, ValidateExtractor {
    
	private String Url = "";
	
	private String extractTime = "";
	
	@ExtractBy("//*div[@class='pagetop grid_48 pagetop2 srcnobg minhigh80']/h1/span[@itemprop='name']/text()")
	private String project_name;
	
	@ExtractBy("//*div[@class='pagetop grid_48 pagetop2 srcnobg minhigh80']/h1/span[@class='appver']/text()")
	private String project_version;
	
	//处理整个description；
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[3]/div[1]/div[4]/div/div/text()")
	private String html1="";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[3]/div[1]/div[4]/div/div/p[1]/text()")
	private String html2="";
    @ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[3]/div[1]/div[4]/div/div/p[2]/text()")
    private String html3="";
    @ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[3]/div[1]/div[4]/div/div/p[3]/text()")
    private String html4="";   
	private String project_description="";
	 
	//处理hits与miss的content
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[4]/table/tbody/tr/td[1]/ul/li/text()")
	private List<String> hits_list=new ArrayList<String>();
	private StringBuffer project_hits_content =new StringBuffer();
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[4]/table/tbody/tr/td[2]/ul/li/text()")
	private List<String> miss_list=new ArrayList<String>();
	private StringBuffer project_miss_content = new StringBuffer();
	
	
	//处理specification table
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[1]/text()")
	private String project_price = " ";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[2]/text()")
	private String project_current_version=" ";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[3]/text()")
	private String project_reviewed_version=" ";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[4]/a/text()")
	private String project_author=" ";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[4]/a/@href")
	private String project_author_url=" ";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[5]/text()")
	private String project_category =" ";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[6]/text()")
	private String project_os_version =" ";
	@ExtractBy("//*[@id='wrapper']/div[2]/div[2]/div[7]/dl/dd[9]/text()")
	private String project_hits = " ";
	
	@ExtractBy("//*div[@class='container_48']/div[@class='grid_48 brd-1-grey1pp']/dl[@class='pspec grid_31']/html()")	
	private String table_html;	
	
	@ExtractBy("//*div[@class='grid_48']/div[@class='grid_17 mgleft_40']/div[@class='hdrating1 nosel']/span/text()")
	private String softpedia_rate =" ";
	@ExtractBy("//*div[@class='grid_48']/div[@class='grid_17 mgleft_40']/div[@class='hdrating1 nosel']/span/text()")
	private String user_rate =" ";
	
	@Override
	public void afterProcess(Page page) {
		// TODO Auto-generated method stub
		this.Url = page.getPageUrl();
		//handle the specification tables;
		this.project_description=html1+html2+html3+html4;
		for(String str : hits_list){
			this.project_hits_content.append(str);
		}
		for(String str : this.miss_list){
			this.project_miss_content.append(str);
		}
		// 处理extractTime
		this.extractTime = DateHandler.getExtractTime();
	}
	
	@Override
	public void validate(Page page) {
		// TODO Auto-generated method stub
		
	}

	private String jsoupHandler(String html, String select_path) {
		Document doc = Jsoup.parse(html);
		Elements ele = doc.select(select_path);
		return ele.text();
	}

	public String getUrl() {
		return Url;
	}

	public void setUrl(String url) {
		Url = url;
	}

	public String getProject_name() {
		return project_name;
	}

	public void setProject_name(String project_name) {
		this.project_name = project_name;
	}

	public String getProject_version() {
		return project_version;
	}

	public void setProject_version(String project_version) {
		this.project_version = project_version;
	}

	public String getProject_description() {
		return project_description;
	}

	public void setProject_description(String project_description) {
		this.project_description = project_description;
	}

	public String getTable_html() {
		return table_html;
	}

	public void setTable_html(String table_html) {
		this.table_html = table_html;
	}

	public String getProject_author() {
		return project_author;
	}

	public void setProject_author(String project_author) {
		this.project_author = project_author;
	}

	public String getProject_author_url() {
		return project_author_url;
	}

	public void setProject_author_url(String project_author_url) {
		this.project_author_url = project_author_url;
	}

	public String getProject_category() {
		return project_category;
	}

	public void setProject_category(String project_category) {
		this.project_category = project_category;
	}

	public String getSoftpedia_rate() {
		return softpedia_rate;
	}

	public void setSoftpedia_rate(String softpedia_rate) {
		this.softpedia_rate = softpedia_rate;
	}

	public String getUser_rate() {
		return user_rate;
	}

	public void setUser_rate(String user_rate) {
		this.user_rate = user_rate;
	}

	public String getHtml1() {
		return html1;
	}

	public void setHtml1(String html1) {
		this.html1 = html1;
	}

	public String getHtml2() {
		return html2;
	}

	public void setHtml2(String html2) {
		this.html2 = html2;
	}

	public String getProject_price() {
		return project_price;
	}

	public void setProject_price(String project_price) {
		this.project_price = project_price;
	}

	public String getProject_current_version() {
		return project_current_version;
	}

	public void setProject_current_version(String project_current_version) {
		this.project_current_version = project_current_version;
	}

	public String getProject_reviewed_version() {
		return project_reviewed_version;
	}

	public void setProject_reviewed_version(String project_reviewed_version) {
		this.project_reviewed_version = project_reviewed_version;
	}

	public String getProject_os_version() {
		return project_os_version;
	}

	public void setProject_os_version(String project_os_version) {
		this.project_os_version = project_os_version;
	}

	public String getProject_hits() {
		return project_hits;
	}

	public void setProject_hits(String project_hits) {
		this.project_hits = project_hits;
	}

	public List<String> getHits_list() {
		return hits_list;
	}

	public void setHits_list(List<String> hits_list) {
		this.hits_list = hits_list;
	}

	public StringBuffer getProject_hits_content() {
		return project_hits_content;
	}

	public void setProject_hits_content(StringBuffer project_hits_content) {
		this.project_hits_content = project_hits_content;
	}

	public List<String> getMiss_list() {
		return miss_list;
	}

	public void setMiss_list(List<String> miss_list) {
		this.miss_list = miss_list;
	}

	public StringBuffer getProject_miss_content() {
		return project_miss_content;
	}

	public void setProject_miss_content(StringBuffer project_miss_content) {
		this.project_miss_content = project_miss_content;
	}
}
